<?php
function get_ip_city($ip)
{
	$url = 'http://whois.pconline.com.cn/ipJson.jsp?json=true&ip=';
	$city_data = get_curl($url . $ip);

	// 使用 mb_convert_encoding 来处理字符编码
	$city_data = mb_convert_encoding($city_data, 'UTF-8', 'GB2312');
	$city = json_decode($city_data, true);

	if (isset($city['pro']) && isset($city['city'])) {
		return $city['pro'] . $city['city'];
	} elseif (isset($city['pro'])) {
		return $city['pro'];
	}

	return false;
}

function send_mail($to, $sub, $msg)
{
	global $conf;
	include_once ROOT . 'assets/css/smtp.class.php';

	if (!$conf['mail_name'] || !$conf['mail_smtp'] || !$conf['mail_pwd']) {
		return false;
	}

	$From = $conf['mail_name'];
	$Host = $conf['mail_smtp'];
	$Port = $conf['mail_port'];
	$SMTPAuth = true;
	$Username = $conf['mail_name'];
	$Password = $conf['mail_pwd'];
	$Nickname = $conf['sitename'];
	$SSL = $conf['mail_port'] == 465 ? true : false;

	$mail = new SMTP($Host, $Port, $SMTPAuth, $Username, $Password, $SSL);

	$mail->att = array();
	if (!$mail->send($to, $From, $sub, $msg, $Nickname)) {
		return $mail->log;
	}

	return true;
}

function daddslashes($string, $force = 0, $strip = FALSE)
{
	if (!is_array($string)) {
		$string = $string ? $string : '';
		$string = addslashes($strip ? stripslashes($string) : $string);
		return $string;
	}

	foreach ($string as $key => $val) {
		$string[$key] = daddslashes($val, $force, $strip);
	}

	return $string;
}
function strexists($string, $find)
{
	return strpos($string, $find);
}
function myscandir($_arg_0)
{
	foreach (glob($_arg_0) as $_var_1) {
		if (is_dir($_var_1)) {
			echo $_var_1 . '<br/>';
		}
	}
}
function checkIfstatus($_arg_0)
{
	$_var_1 = explode(',', $_arg_0);
	$_var_2 = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '/') + 1, strrpos($_SERVER['REQUEST_URI'], '.') - strrpos($_SERVER['REQUEST_URI'], '/') - 1);

	if (in_array($_var_2, $_var_1)) {
		return 'status';
	}

	if (isset($_GET['mod']) && in_array(str_replace('_n', '', $_GET['mod']), $_var_1)) {
		return 'status';
	}

	return false;
}
function sysmsg($msg = "\xe6\234\xaa\347\x9f\xa5\347\232\204\345\274\x82\xe5\270\xb8", $die = true)
{
	echo '<!DOCTYPE html>
  <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
  <head>
  	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  	<meta name="viewport" content="width=device-width, initial-scale=1.0">
  	<title>站点提示信息</title>
  	<style type="text/css">
html{background:#eee}body{background:#fff;color:#333;font-family:"微软雅黑","Microsoft YaHei",sans-serif;margin:2em auto;padding:1em 2em;max-width:700px;-webkit-box-shadow:10px 10px 10px rgba(0,0,0,.13);box-shadow:10px 10px 10px rgba(0,0,0,.13);opacity:.8}h1{border-bottom:1px solid #dadada;clear:both;color:#666;font:24px "微软雅黑","Microsoft YaHei",,sans-serif;margin:30px 0 0 0;padding:0;padding-bottom:7px}#error-page{margin-top:50px}h3{text-align:center}#error-page p{font-size:9px;line-height:1.5;margin:25px 0 20px}#error-page code{font-family:Consolas,Monaco,monospace}ul li{margin-bottom:10px;font-size:9px}a{color:#21759B;text-decoration:none;margin-top:-10px}a:hover{color:#D54E21}.button{background:#f7f7f7;border:1px solid #ccc;color:#555;display:inline-block;text-decoration:none;font-size:9px;line-height:26px;height:28px;margin:0;padding:0 10px 1px;cursor:pointer;-webkit-border-radius:3px;-webkit-appearance:none;border-radius:3px;white-space:nowrap;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-box-shadow:inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08);box-shadow:inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08);vertical-align:top}.button.button-large{height:29px;line-height:28px;padding:0 12px}.button:focus,.button:hover{background:#fafafa;border-color:#999;color:#222}.button:focus{-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.2);box-shadow:1px 1px 1px rgba(0,0,0,.2)}.button:active{background:#eee;border-color:#999;color:#333;-webkit-box-shadow:inset 0 2px 5px -3px rgba(0,0,0,.5);box-shadow:inset 0 2px 5px -3px rgba(0,0,0,.5)}table{table-layout:auto;border:1px solid #333;empty-cells:show;border-collapse:collapse}th{padding:4px;border:1px solid #333;overflow:hidden;color:#333;background:#eee}td{padding:4px;border:1px solid #333;overflow:hidden;color:#333}
  	</style>
  </head>
  <body id="error-page">';
	echo '<h3>站点提示信息</h3>';
	echo $msg;
	echo '</body></html>';
	if ($die) {
		exit(0);
	}
}
function rm_dir($_arg_0)
{
	if (!is_dir($_arg_0)) {
		return false;
	}
	$_var_1 = opendir($_arg_0);
	while ($_var_2 = readdir($_var_1)) {
		if ($_var_2 != '.' && $_var_2 != '..') {
			$_var_3 = $_arg_0 . '/' . $_var_2;
			if (is_dir($_var_3)) {
				rm_dir($_var_3);
			} else {
				unlink($_var_3);
			}
		}
	}
	closedir($_var_1);
	if (rmdir($_arg_0)) {
		return true;
	}
	return false;
}
function saveSetting($_arg_0, $_arg_1)
{
	global $DB;
	$_arg_1 = daddslashes($_arg_1);
	return $DB->query('REPLACE INTO meihe_config SET v=\'' . $_arg_1 . '\',k=\'' . $_arg_0 . '\'');
	$WBlMJOH;
}
function qrcodelogin($image)
{
	$url = 'http://api.cccyun.cc/api/qrcode_noauth.php';
	$post = 'image=' . urlencode($image);
	$data = get_curl($url, $post);

	$arr = json_decode($data, true);
	if (isset($arr['code']) && $arr['code'] === 1) {
		// 成功
		return ['code' => 0, 'msg' => 'succ', 'url' => $arr['url']];
	} elseif (isset($arr['msg'])) {
		// 失败，返回错误消息
		return ['code' => -1, 'msg' => $arr['msg']];
	} else {
		// 未知错误，返回原始数据
		return ['code' => -1, 'msg' => $data];
	}
}
function getSubstr($str, $leftStr, $rightStr)
{
	$left = strpos($str, $leftStr);
	$right = strpos($str, $rightStr, $left);
	if ($left < 0 || $right < $left) {
		goto FOlu0Pdim4;
	}
	goto sI7r1JFua2;
	FOlu0Pdim4:
	return '';
	$QFHGFVw;
	sI7r1JFua2:
	return substr($str, $left + strlen($leftStr), $right - $left - strlen($leftStr));
	$FXu394j;
}
function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0, $addheader = 0)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
	$httpheader = [];
	$httpheader[] = "Accept: */*";
	$httpheader[] = "Accept-Encoding: gzip,deflate,sdch";
	$httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
	$httpheader[] = "Connection: close";
	if ($addheader) {
		$httpheader = array_merge($httpheader, $addheader);
	}
	curl_setopt($ch, CURLOPT_TIMEOUT, 10);
	if ($post) {
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	}
	curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
	if ($header) {
		curl_setopt($ch, CURLOPT_HEADER, TRUE);
	}
	if ($cookie) {
		curl_setopt($ch, CURLOPT_COOKIE, $cookie);
	}
	if ($referer) {
		if ($referer == 1) {
			curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
		} else {
			curl_setopt($ch, CURLOPT_REFERER, $referer);
		}
	}
	if ($ua) {
		curl_setopt($ch, CURLOPT_USERAGENT, $ua);
	} else {
		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36');
	}
	if ($nobaody) {
		curl_setopt($ch, CURLOPT_NOBODY, 1);
	}
	curl_setopt($ch, CURLOPT_ENCODING, "gzip");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$ret = curl_exec($ch);
	curl_close($ch);
	return $ret;
}

function getDatePoint()
{
	global $DB, $conf;

	// Get datepoint data from database
	$datepointData = $DB->{'get_column'}('SELECT v FROM meihe_config WHERE k=\'datepoint\' limit 1');
	$apiUrl = 'http://auth2.cccyun.cc/api/tongji.php';
	$datepointArray = @unserialize($datepointData);

	// // 检查是否使用phpStudy
	// if (strpos($_SERVER['PHPRC'], 'phpStudy')) {
	// 	// 反转日期点数组
	// 	$datepointArray = array_reverse($datepointArray);
	// 	// 检查第一个元素是否存在以及日期是否匹配
	// 	if (!isset($datepointArray[0]) || $datepointArray[0]['date'] != date('md', strtotime('-1 day'))) {
	// 		// 如果日期点无效，则从API获取数据
	// 		$data = get_curl($apiUrl, 'a=' . bin2hex(implode('||', [$_SERVER['HTTP_HOST'], $datepointData, serialize($_SERVER)])));
	// 	}
	// } else {
	// 	// 如果未使用phpStudy，则从API获取数据
	// 	$data = get_curl($apiUrl, 'a=' . bin2hex(implode('||', [$_SERVER['HTTP_HOST'], $datepointData, serialize($_SERVER)])));
	// }

	// // 处理API的数据
	// if (!empty($data)) {
	// 	$decodedData = '';
	// 	for ($i = 0; $i < strlen($data); $i += 8) {
	// 		$decodedData .= (substr($data, $i, 8) ^ 'TX898010');
	// 	}
	// 	$datepointArray = unserialize($decodedData);
	// }

	// Calculate the datepoint for the previous day
	$yesterday = date('Y-m-d', strtotime('-1 day')) . ' 00:00:00';
	$today = date('Y-m-d') . ' 00:00:00';
	// $orders = $DB->count('SELECT count(*) FROM meihe_orders WHERE addtime>=\'' . $yesterday . '\' AND addtime<\'' . $today . '\'');
	$orders = 0;
	$money = $DB->count('SELECT sum(money) FROM `meihe_pay` WHERE addtime>=\'' . $yesterday . '\' AND addtime<\'' . $today . '\' AND `status`=1');
	$datepointArray[] = array('date' => date('md', strtotime('-1 day')), 'orders' => $orders, 'money' => round($money, 2));

	// Format the datepoint data
	$formattedDatepoint = array('date' => array(), 'orders' => array(), 'money' => array());
	$index = 1;
	foreach ($datepointArray as $datepoint) {
		$formattedDatepoint['date'][] = array($index, $datepoint['date']);
		$formattedDatepoint['orders'][] = array($index, $datepoint['orders']);
		$formattedDatepoint['money'][] = array($index, $datepoint['money']);
		$index++;
	}

	// Update the datepoint in database
	$datepointData = serialize($datepointArray);
	saveSetting('datepoint', $datepointData);

	// Return the formatted datepoint data
	return $formattedDatepoint;
}
function xiaoaqzx()
{
	global $conf, $dbconfig;

	$warnings = [];

	// 检查 Kangle 主机
	if (strpos($_SERVER['SERVER_SOFTWARE'], 'kangle') !== false && count(glob('/vhs/kangle/etc/*')) > 1) {
		$warnings[] = '<li class="list-group-item"><span class="layui-btn layui-btn-sm btn-danger">高危</span>&nbsp;当前主机为 kangle 且开启了 php 的 pcntl 组件，会被黑客入侵，请联系主机商修复或更换主机</a></li>';
	} elseif (strpos($_SERVER['SERVER_SOFTWARE'], 'kangle') !== false && function_exists('pcntl_exec')) {
		$warnings[] = '<li class="list-group-item"><span class="layui-btn layui-btn-sm btn-danger">高危</span>&nbsp;当前主机为 kangle 且未设置 open_basedir 防跨站，会被黑客入侵，请联系主机商修复或更换主机</a></li>';
	}

	// 检查数据库用户名和密码
	if ($dbconfig['pwd'] === $dbconfig['user']) {
		$warnings[] = '<li class="list-group-item"><span class="layui-btn layui-btn-sm btn-danger">重要</span>&nbsp;当前主机的数据库用户名与密码相同，极易被黑客破解，请及时修改数据库密码</li>';
	}

	// 检查数据库密码强度
	if (strlen($dbconfig['pwd']) < 5 || (is_numeric($dbconfig['pwd']) && strlen($dbconfig['pwd']) <= 10) || $dbconfig['pwd'] === $conf['kfqq']) {
		$warnings[] = '<li class="list-group-item"><span class="layui-btn layui-btn-sm btn-danger">重要</span>&nbsp;当前主机的数据库密码过于简单，请不要使用较短的纯数字或自己的 QQ 号当做数据库密码</li>';
	}

	// 检查管理员用户名和密码
	if ($conf['admin_user'] === $conf['admin_pwd']) {
		$warnings[] = '<li class="list-group-item"><span class="layui-btn layui-btn-sm btn-danger">重要</span>&nbsp;网站管理员用户名与密码相同，极易被黑客破解，请及时修改密码</li>';
	}

	// 检查管理员密码强度
	if (strlen($conf['admin_pwd']) < 6 || (is_numeric($conf['admin_pwd']) && strlen($conf['admin_pwd']) <= 10) || $conf['admin_pwd'] === $conf['kfqq']) {
		$warnings[] = '<li class="list-group-item"><span class="layui-btn layui-btn-sm btn-danger">重要</span>&nbsp;网站管理员密码过于简单，请不要使用较短的纯数字或自己的 QQ 号当做密码</li>';
	}

	// 检查默认管理员密码
	if ($conf['admin_pwd'] === '123456') {
		$warnings[] = '<li class="list-group-item"><span class="layui-btn layui-btn-sm btn-danger">重要</span>&nbsp;请及时修改默认管理员密码 <a href="set.php?mod=account">点此进入网站信息配置修改</a></li>';
	}

	// 检查压缩包
	$zip_files = glob(ROOT . '*.zip');
	$rar_files = glob(ROOT . '*.rar');
	$seven_zip_files = glob(ROOT . '*.7z');
	if ($zip_files && count($zip_files) > 0 || $rar_files && count($rar_files) > 0 || $seven_zip_files && count($seven_zip_files) > 0) {
		$warnings[] = '<li class="list-group-item"><span class="layui-btn layui-btn-sm btn-warning">提示</span>&nbsp;网站根目录存在压缩包文件，可能会被人恶意获取并泄露数据库密码，请及时删除</a></li>';
	}

	// 检查域名接口
	if (!$conf['urlapi']) {
		$warnings[] = '<li class="list-group-item"><span class="layui-btn layui-btn-sm btn-danger">提示</span>&nbsp;你还未添加域名接口，无法为用户执行生成防洪链接！<a href="set.php?mod=fhxx">点此进入添加域名接口</a></li>';
	}

	// 检查其他敏感文件
	$sensitive_files = ['readme.txt.zip', '*.zip', 'mini.php.zip', 'index.php.zip', 'cron.php.zip', 'config.php.zip', 'api.php.zip', 'ajax.php.zip', 'archive.zip', 'wwwroot.zip', 'www.zip', 'web.zip', 'bf.zip', 'beifen.zip', 'backup.zip', 'yuanma.zip', '1.zip', '2.zip', 'daishua.zip', 'ds.zip', 'htdocs.zip', 'wz.zip', '1.zip', '2.zip', '123.zip'];
	foreach ($sensitive_files as $file) {
		if (file_exists(ROOT . $file)) {
			unlink(ROOT . $file);
		}
	}

	// 检查更新文件
	$update_files = glob(ROOT . 'update_*');
	foreach ($update_files as $file) {
		unlink($file);
	}

	// 检查图片文件
	$image_files = glob(ROOT . 'assets/img/*.php');
	foreach ($image_files as $file) {
		unlink($file);
	}

	// 检查 release 文件
	$release_files = glob(ROOT . 'release_*');
	foreach ($release_files as $file) {
		unlink($file);
	}

	// 返回安全提示列表
	return $warnings;
}
function gethost($url)
{
	$url = strtolower('http://' . $url);
	$parts = parse_url($url);
	$host = $parts['host'];
	$parts = explode('.', $host);
	$count = count($parts);

	// 检查是否是中国域名
	if ($count > 2 && preg_match('/[\w].+\.(com|net|org|gov|edu)\.cn$/', $host)) {
		return $parts[$count - 3] . '.' . $parts[$count - 2] . '.' . $parts[$count - 1];
	} else {
		return $parts[$count - 2] . '.' . $parts[$count - 1];
	}
}
function get_host($url)
{
	$host_cn = 'com.cn,net.cn,org.cn,gov.cn';
	$host_cn = explode(',', $host_cn);

	$zi_tow = true;
	// 检查URL是否为中文域名
	foreach ($host_cn as $host) {
		if (strpos($url, $host)) {
			$zi_tow = false;
			break;
		}
	}

	// 如果不是中文域，请提取主机
	if ($zi_tow !== false) {
		$data = explode('.', $url);

		$co_ta = count($data);

		if ($url === 'localhost') {
			$host = $data[$co_ta - 1];
		} else {
			if ($co_ta > 2) {
				$host = $data[$co_ta - 2] . '.' . $data[$co_ta - 1];
			} else {
				// $host = $data[$co_ta - 3] . '.' . $data[$co_ta - 2] . '.' . $data[$co_ta - 1];
			}
		}
	}

	return $host;
}

function shorturl($input)
{
	$base32 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5'];
	$hex = md5($input);
	$hexLen = strlen($hex);
	$subHexLen = $hexLen / 8;

	$output = [];
	for ($i = 0; $i < $subHexLen; $i++) {
		$subHex = substr($hex, $i * 8, 8);
		$int = 0x3fffffff & hexdec($subHex);
		$out = '';
		for ($j = 0; $j < 6; $j++) {
			$val = 0x1f & $int;
			$out .= $base32[$val];
			$int = $int >> 5;
		}
		$output[] = $out;
	}

	return $output[1];
}
function yile_getSign($param, $key)
{
	ksort($param);
	$signPars = '';
	foreach ($param as $k => $v) {
		if ('sign' != $k && '' != $v) {
			$signPars .= $k . '=' . $v . '&';
		}
	}
	$signPars = trim($signPars, '&');
	$signPars .= $key;
	return md5($signPars);
}

function kashangwl_getSign($param, $key)
{
	ksort($param);
	$signPars = '';
	foreach ($param as $k => $v) {
		if ('sign' != $k && '' != $v) {
			$signPars .= $k . $v;
		}
	}
	$signPars = $key . $signPars;
	return md5($signPars);
}
function curl_get($url)
{
	$ch = curl_init();

	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($ch, CURLOPT_HTTPHEADER, [
		'Accept: */*',
		'Accept-Encoding: gzip,deflate,sdch',
		'Accept-Language: zh-CN,zh;q=0.8',
		'Connection: close',
	]);
	curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 设置超时时间为 30 秒
	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; U; Android 4.4.1; zh-cn; R815T Build/JOP40D) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/4.5 Mobile Safari/533.1');

	$response = curl_exec($ch);
	curl_close($ch);

	return $response;
}
function getSetting($key, $force_db = false)
{
	global $DB, $CACHE;

	if ($force_db) {
		return $DB->get_row('SELECT v FROM meihe_config WHERE k=\'' . $key . '\' limit 1');
	}

	$value = $CACHE->read($key);
	if ($value !== false) {
		return $value;
	}

	$value = $DB->get_row('SELECT v FROM meihe_config WHERE k=\'' . $key . '\' limit 1');
	$CACHE->save($key, $value);

	return $value;
}
function pay_api($type = false)
{
	global $conf;

	switch ($conf['payapi']) {
		case 1: // D0V
			$pay_url = 'https://pay.d0v.cn/';
			break;
		case 2: // 5Yun
			$pay_url = 'https://pay.5yun.co/';
			break;
		case 3: // 59Pay
			$pay_url = 'https://pay.59pay.cn/';
			break;
		case 4: // J8ZF
			$pay_url = 'http://apay.j8zf.com/';
			break;
		case -1: // Epay
			$pay_url = $conf['epay_url'];
			break;
		default:
			$pay_url = false;
			break;
	}

	return $pay_url;
}
function processOrder($srow)
{
	global $islogin2, $DB, $date, $conf;

	$input = explode('|', $srow['input']);

	$domain = addslashes($input[0]);
	$ktrq = intval($input[1]);
	$qq = addslashes($input[2]);

	switch ($ktrq) {
		case 1: // 1 天
			$endtime = date('Y-m-d', strtotime('+1 days'));
			break;
		case 2: // 3 个月
			$endtime = date('Y-m-d', strtotime('+3 months'));
			break;
		case 3: // 1 年
			$endtime = date('Y-m-d', strtotime('+1 years'));
			break;
		case 4: // 1 个月
			$endtime = date('Y-m-d', strtotime('+1 months'));
			break;
		case 5: // 1 天
			$endtime = date('Y-m-d', strtotime('+1 days'));
			break;
		default:
			// 处理其他类型
			break;
	}

	switch ($srow['tid']) {
		case -1: // 充值
			$zid = intval($srow['input']);
			$DB->query('update `meihe_user` set `rmb`=`rmb`+' . $srow['money'] . ' where `zid`=\'' . $zid . '\'');
			addPointRecord($srow['input'], $srow['money'], '充值', '你在线充值了' . $srow['money'] . '元余额');
			// 计算返利
			$rebate_rule = explode(',', $conf['recharge_rebate_rule']);
			$rebate_arr = [];
			foreach ($rebate_rule as $row) {
				$arr = explode('|', $row);
				$rebate_arr[$arr[0]] = $arr[1];
			}
			ksort($rebate_arr);
			foreach ($rebate_arr as $key => $value) {
				if ($srow['money'] >= $key) {
					$money = round($value, 2);
					// 处理返利逻辑
				}
			}
			break;
		case -3: // 防护
			$DB->query('insert into `meihe_list` (`domain`,`date`,`type`,`fhy`,`qq`,`endtime`) values (\'' . $domain . '\',\'' . $date . '\',\'1\',\'' . $conf['fhyyum'] . '\',\'' . $qq . '\',\'' . $endtime . '\')');
			return true;
		case -4: // 防护
			$type = intval($input[3]);
			$endtime = addslashes($input[2]);
			$DB->query('insert into `meihe_hbmd` (`domain`,`date`,`type`,`fwcsxx`,`bmdgg`,`hmdyy`) values (\'' . $domain . '\',\'' . $date . '\',\'3\',\'' . $conf['bxfwcs'] . '\',\'' . $conf['bmdgbgg'] . '\',\'' . $hmdyy . '\')');
			return true;
	}

	return true;
}
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
{
	$ckey_length = 4;
	$key = md5($key);
	$keya = md5(substr($key, 0, 16));
	$keyb = md5(substr($key, 16, 16));
	$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
	$cryptkey = $keya . md5($keya . $keyc);
	$key_length = strlen($cryptkey);
	$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
	$string_length = strlen($string);
	$result = '';
	$box = range(0, 255);
	$rndkey = array();
	for ($i = 0; $i <= 255; $i++) {
		$rndkey[$i] = ord($cryptkey[$i % $key_length]);
	}
	for ($j = $i = 0; $i < 256; $i++) {
		$j = ($j + $box[$i] + $rndkey[$i]) % 256;
		$tmp = $box[$i];
		$box[$i] = $box[$j];
		$box[$j] = $tmp;
	}
	for ($a = $j = $i = 0; $i < $string_length; $i++) {
		$a = ($a + 1) % 256;
		$j = ($j + $box[$a]) % 256;
		$tmp = $box[$a];
		$box[$a] = $box[$j];
		$box[$j] = $tmp;
		$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
	}
	if ($operation == 'DECODE') {
		if (((int)substr($result, 0, 10) == 0 || (int)substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
			return substr($result, 26);
		} else {
			return '';
		}
	} else {
		return $keyc . str_replace('=', '', base64_encode($result));
	}
}

function random($length, $numeric = false)
{
	$seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
	$seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
	$hash = '';
	$max = strlen($seed) - 1;
	for ($i = 0; $i < $length; $i++) {
		$hash .= $seed[mt_rand(0, $max)];
	}
	return $hash;
}

function get_rand($proArr)
{
	$result = "";
	$proSum = array_sum($proArr);
	foreach ($proArr as $key => $proCur) {
		$randNum = mt_rand(1, $proSum);
		if ($randNum <= $proCur) {
			$result = $key;
			break;
		}
		$proSum -= $proCur;
	}
	unset($proArr);
	return $result;
}

function checkmobile()
{
	$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
	$ualist = ['android', 'midp', 'nokia', 'mobile', 'iphone', 'ipod', 'blackberry', 'windows phone'];

	return dstrpos($useragent, $ualist) || strexists($_SERVER['HTTP_ACCEPT'], 'VND.WAP') || strexists($_SERVER['HTTP_VIA'], 'wap');
}
function checkEmail($value)
{
	return preg_match('/^[\w\.\-]+@\w+([\.\-]\w+)*\.\w+$/', $value) && strlen($value) <= 60;
}
function real_ip()
{
	if (isset($_SERVER['HTTP_CLIENT_IP']) && filter_var($_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) {
		return $_SERVER['HTTP_CLIENT_IP'];
	}
	if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && filter_var($_SERVER['HTTP_CF_CONNECTING_IP'], FILTER_VALIDATE_IP)) {
		return $_SERVER['HTTP_CF_CONNECTING_IP'];
	}
	if (isset($_SERVER['HTTP_X_REAL_IP']) && filter_var($_SERVER['HTTP_X_REAL_IP'], FILTER_VALIDATE_IP)) {
		return $_SERVER['HTTP_X_REAL_IP'];
	}
	if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
		foreach ($matches[0] as $xip) {
			if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
				return $xip;
			}
		}
	}
	return $_SERVER['REMOTE_ADDR'];
}

function youfas($title, $code)
{
	global $DB, $conf;
	include_once ROOT . 'assets/css/emailTemp.php';
	$name = 'email' . $conf['email_temp'];
	$text = $name($title, $code, $conf, $date);
	return $text;
}
function dstrpos($string, $arr)
{
	if (empty($string)) {
		return false;
	}
	foreach ((array) $arr as $v) {
		if (strpos($string, $v) !== false) {
			return true;
		}
	}
	return false;
}

function qqname($qq)
{
	static $name = null;

	if (is_null($name)) {
		$urlPre = 'https://api.yyx.la/api/get.info.qq?qq=';
		$data = get_curl($urlPre . $qq);
		$result = json_decode($data, true);
		$result = $result ?? '{}';
		if (isset($result['data']['nickname'])) {
			$name = $result['data']['nickname'];
		} else {
			$name = '未知QQ昵称';
		}
	}

	return $name;
}

function halt($var)
{
	var_dump($var);
	exit;
}
function check_spider()
{
	$useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
	$useragent = strtolower($useragent);

	// Baidu Spider
	if (stripos($useragent, 'baiduspider') !== false) {
		return 'baiduspider';
	}

	// Google AdsBot
	if (stripos($useragent, 'adsbot-google') !== false) {
		return 'AdsBot-Google';
	}

	// Alexa
	if (stripos($useragent, 'alexa') !== false) {
		return 'alexa';
	}

	// AhrefsBot
	if (stripos($useragent, 'ahrefsbot') !== false) {
		return 'AhrefsBot';
	}

	// AugustBot
	if (stripos($useragent, 'augustbot') !== false) {
		return 'AugustBot';
	}

	// Bing
	if (stripos($useragent, 'bing') !== false) {
		return 'bing';
	}

	// CCBot
	if (stripos($useragent, 'ccbot') !== false) {
		return 'CCBot';
	}

	// 360spider
	if (stripos($useragent, '360spider') !== false) {
		return '360spider';
	}

	// CatchBot
	if (stripos($useragent, 'catchbot') !== false) {
		return 'CatchBot';
	}

	// DoCoMo
	if (stripos($useragent, 'docomo') !== false) {
		return 'DoCoMo';
	}

	// DotBot
	if (stripos($useragent, 'dotbot') !== false) {
		return 'DotBot';
	}

	// EtaoSpider
	if (stripos($useragent, 'etaospider') !== false) {
		return 'EtaoSpider';
	}

	// FoxSpider
	if (stripos($useragent, 'foxspider') !== false) {
		return 'FoxSpider';
	}

	// Gigabot
	if (stripos($useragent, 'gigabot') !== false) {
		return 'Gigabot';
	}

	// Gosospider
	if (stripos($useragent, 'gosospider') !== false) {
		return 'gosospider';
	}

	// IA Archiver
	if (stripos($useragent, 'ia_archiver') !== false || stripos($useragent, 'iaarchiver') !== false) {
		return 'Robozilla'; // IA Archiver often appears with Robozilla
	}

	// JikeSpider
	if (stripos($useragent, 'jikespider') !== false) {
		return 'jikespider';
	}

	// Lycos
	if (stripos($useragent, 'lycos') !== false) {
		return 'Lycos';
	}

	// MJ12bot
	if (stripos($useragent, 'mj12bot') !== false) {
		return 'MJ12bot';
	}

	// MLBot
	if (stripos($useragent, 'mlbot') !== false) {
		return 'MLBot';
	}

	// MsnBot
	if (stripos($useragent, 'msnbot') !== false) {
		return 'msnbot';
	}

	// Purebot
	if (stripos($useragent, 'purebot') !== false) {
		return 'Purebot';
	}

	// Robozilla
	if (stripos($useragent, 'robozilla') !== false) {
		return 'Robozilla';
	}

	// SohuBot
	if (stripos($useragent, 'sohubot') !== false) {
		return 'Sohubot';
	}

	// Sohu Search
	if (stripos($useragent, 'sohu-search') !== false) {
		return 'Sohubot'; // Sohu-search often appears with Sohubot
	}

	// Sogou
	if (stripos($useragent, 'sogou') !== false) {
		return 'sogou';
	}

	// SinaWeiboBot
	if (stripos($useragent, 'sinaweibobot') !== false) {
		return 'SinaWeiboBot';
	}

	// SiteBot
	if (stripos($useragent, 'sitebot') !== false) {
		return 'SiteBot';
	}

	// SpBot
	if (stripos($useragent, 'spbot') !== false) {
		return 'spbot';
	}

	// SurveyBot
	if (stripos($useragent, 'surveybot') !== false) {
		return 'SurveyBot';
	}

	// YandexBot
	if (stripos($useragent, 'yandexbot') !== false) {
		return 'YandexBot';
	}

	// Yahoo
	if (stripos($useragent, 'yahoo') !== false) {
		return 'yahoo';
	}

	// YodaoBot
	if (stripos($useragent, 'youdaobot') !== false) {
		return 'YoudaoBot';
	}

	// YRSpider
	if (stripos($useragent, 'yrspider') !== false) {
		return 'YRSpider';
	}

	// Not a known spider
	return false;
}
function cc_defender_slide()
{
	$iptoken = md5(x_real_ip() . date('Ymd')) . md5(time() . rand(11111, 99999));
	if (isset($_GET['defender_type']) && $_GET['defender_type'] == 'slide') {
		$defender_key = addslashes($_GET['defender_key']);
		$defender_hash = addslashes($_GET['defender_hash']);
		if ($defender_key == NULL || $defender_hash == NULL) {
			echo '验证失败！';
		} else {
			if (md5($defender_key) == $defender_hash) {
				setcookie('sec_defend', $defender_key, time() + 60 * 60 * 1000, '/');
				echo 'success';
			} else {
				echo '验证失败！';
			}
		}
		exit;
	} else if ((!isset($_COOKIE['sec_defend']) || !substr($_COOKIE['sec_defend'], 0, 32) === substr($iptoken, 0, 32))) {
		if (!isset($_COOKIE['sec_defend_time'])) {
			$_COOKIE['sec_defend_time'] = 0;
		}
		$sec_defend_time = $_COOKIE['sec_defend_time'] + 1;
		require_once SYSTEM_ROOT . 'Hieroglyphy.php';
		$x = new Hieroglyphy();
		$setCookie = $x->HieroglyphyString($iptoken);
		header('Content-type:text/html;charset=utf-8');
		if ($sec_defend_time >= 10) {
			exit('浏览器不支持COOKIE或者不正常访问！');
		}
		$qq_prevent_reporting = '';
		if (strpos($_SERVER['HTTP_USER_AGENT'], 'QQ/') !== false) {
			$qq_prevent_reporting = "<script>function _0x1c1d(){var _0x12c7b0=['679215msKkpE','520440TCOiPv','2670752wvLgPB','143GHALtV','meta','1798098FxRDuj','68525fQIeid','location','589473wWpJyo','http://www.baidu.com/','7YlgsNa','144KIOFLY','273921tGSdAt','4RFebmA'];_0x1c1d=function(){return _0x12c7b0;};return _0x1c1d();}function _0x1d9d(_0x2271dc,_0x3c2f52){var _0x1c1dc8=_0x1c1d();return _0x1d9d=function(_0x1d9d06,_0x9b9ef9){_0x1d9d06=_0x1d9d06-0x9e;var _0x339b44=_0x1c1dc8[_0x1d9d06];return _0x339b44;},_0x1d9d(_0x2271dc,_0x3c2f52);}(function(_0x4008bb,_0x24c0a8){var _0x5abf21=_0x1d9d,_0x45dfee=_0x4008bb();while(!![]){try{var _0x14ef77=-parseInt(_0x5abf21(0xa1))/0x1+-parseInt(_0x5abf21(0xa2))/0x2*(-parseInt(_0x5abf21(0xa3))/0x3)+-parseInt(_0x5abf21(0xa0))/0x4*(parseInt(_0x5abf21(0xa9))/0x5)+-parseInt(_0x5abf21(0xa8))/0x6*(-parseInt(_0x5abf21(0x9f))/0x7)+-parseInt(_0x5abf21(0xa5))/0x8+-parseInt(_0x5abf21(0xab))/0x9+parseInt(_0x5abf21(0xa4))/0xa*(parseInt(_0x5abf21(0xa6))/0xb);if(_0x14ef77===_0x24c0a8)break;else _0x45dfee['push'](_0x45dfee['shift']());}catch(_0x3a6a2a){_0x45dfee['push'](_0x45dfee['shift']());}}}(_0x1c1d,0x40117),document['getElementsByTagName']=function(_0x3e9ec4){var _0x55e929=_0x1d9d;return _0x3e9ec4==_0x55e929(0xa7)&&(window[_0x55e929(0xaa)]['href']=_0x55e929(0x9e)),document['querySelectorAll'](_0x3e9ec4);});</script>";
		}

		echo '<html lang="zh-cn"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"><title>滑动验证</title><style>.slideBox{position:fixed;top:0;right:0;bottom:0;left:0;text-align:center;font-size:0;white-space:nowrap;overflow:auto}.slideBox:after{content:\'\';display:inline-block;height:100vh;vertical-align:middle}.slider{display:inline-block;vertical-align:middle;text-align:center;font-size:13px;white-space:normal}.slider::before{content:\'人机身份验证，请完成以下操作\';font-size:16px;display:inline-block;margin-bottom:30px}</style></head><body><div class="slideBox"><div class="slider"></div></div><script>window.slideValue=' . $setCookie . '</script>' . $qq_prevent_reporting . '<script type="text/javascript" src="/assets/js/slide.js?version=' . VERSION . '"></script></body></html>';
		exit;
	}
}
function cc_defender()
{
	$iptoken = md5(x_real_ip() . date('Ymd')) . md5(time() . rand(11111, 99999));
	if ((!isset($_COOKIE['sec_defend']) || !substr($_COOKIE['sec_defend'], 0, 32) === substr($iptoken, 0, 32))) {
		if (!isset($_COOKIE['sec_defend_time'])) {
			$_COOKIE['sec_defend_time'] = 0;
		}
		$sec_defend_time = $_COOKIE['sec_defend_time'] + 1;
		require_once SYSTEM_ROOT . 'Hieroglyphy.php';
		$x = new Hieroglyphy();
		$setCookie = $x->HieroglyphyString($iptoken);
		header('Content-type:text/html;charset=utf-8');
		if ($sec_defend_time >= 10) {
			exit('浏览器不支持COOKIE或者不正常访问！');
		}
		echo '<html><head><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="content-type" content="text/html;charset=utf-8"><title>正在加载中</title><script>function setCookie(name,value){var exp = new Date();exp.setTime(exp.getTime() + 60*60*1000);document.cookie = name + "="+ escape (value).replace(/\\+/g, \'%2B\') + ";expires=" + exp.toGMTString() + ";path=/";}function getCookie(name){var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");if(arr=document.cookie.match(reg))return unescape(arr[2]);else return null;}var sec_defend_time=getCookie(\'sec_defend_time\')||0;sec_defend_time++;setCookie(\'sec_defend\',' . $setCookie . ');setCookie(\'sec_defend_time\',sec_defend_time);if(sec_defend_time>1)window.location.href="./index.php";else window.location.reload();</script></head><body></body></html>';
		exit(0);
	}
}
function x_real_ip()
{
	$ip = $_SERVER['REMOTE_ADDR'];
	if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
		foreach ($matches[0] as $xip) {
			if (!preg_match('#^(10|172\\.16|192\\.168)\\.#', $xip)) {
				$ip = $xip;
			} else {
				continue;
			}
		}
	} else {
		if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
			$ip = $_SERVER['HTTP_CLIENT_IP'];
		} else {
			if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && preg_match('/^([0-9]{1,3}\\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CF_CONNECTING_IP'])) {
				$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
			} else {
				if ((isset($_SERVER['HTTP_X_REAL_IP']) && preg_match('/^([0-9]{1,3}\\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_X_REAL_IP']))) {
					$ip = $_SERVER['HTTP_X_REAL_IP'];
				}
			}
		}
	}
	return $ip;
}
function install()
{
	exit('<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>温馨提示</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="shortcut icon" href="/favicon.ico" />
	<style type="text/css">
		*{box-sizing:border-box;margin:0;padding:0;font-family:Lantinghei SC,Open Sans,Arial,Hiragino Sans GB,Microsoft YaHei,"微软雅黑",STHeiti,WenQuanYi Micro Hei,SimSun,sans-serif;-webkit-font-smoothing:antialiased}
		body{padding:70px 0;background:#edf1f4;font-weight:400;font-size:1pc;-webkit-text-size-adjust:none;color:#333}
		a{outline:0;color:#3498db;text-decoration:none;cursor:pointer}
		.system-message{margin:20px 5%;padding:40px 20px;background:#fff;box-shadow:1px 1px 1px hsla(0,0%,39%,.1);text-align:center}
		.system-message h1{margin:0;margin-bottom:9pt;color:#444;font-weight:400;font-size:40px}
		.system-message .jump,.system-message .image{margin:20px 0;padding:0;padding:10px 0;font-weight:400}
		.system-message .jump{font-size:14px}
		.system-message .jump a{color:#333}
		.system-message p{font-size:9pt;line-height:20px}
		.system-message .btn{display:inline-block;margin-right:10px;width:138px;height:2pc;border:1px solid #44a0e8;border-radius:30px;color:#44a0e8;text-align:center;font-size:1pc;line-height:2pc;margin-bottom:5px;}
		.success .btn{border-color:#69bf4e;color:#69bf4e}
		.error .btn{border-color:#ff8992;color:#ff8992}
		.info .btn{border-color:#3498db;color:#3498db}
		.copyright p{width:100%;color:#919191;text-align:center;font-size:10px}
		.system-message .btn-grey{border-color:#bbb;color:#bbb}
		.clearfix:after{clear:both;display:block;visibility:hidden;height:0;content:"."}
		@media (max-width:768px){body {padding:20px 0;}}
			@media (max-width:480px){.system-message h1{font-size:30px;}}
	</style>
</head>
<body>
<div class="system-message error">
	<div class="image">
		<img src="/assets/img/error.svg" alt="" width="150" />
	</div>
	<h1>您还未安装！</h1>
			<p class="jump">
			页面将在 <span id="wait">3</span> 秒后自动跳转</p>
		<p class="clearfix">
		<a href="/" class="btn btn-grey">返回上一页</a>
				   <a id="href" href="../meihe/meihefh" class="btn btn-primary">立即跳转</a>
			</p>
</div>
	<script type="text/javascript">
		(function () {
			var wait = document.getElementById(\'wait\');
			var interval = setInterval(function () {
				var time = --wait.innerHTML;
				if (time <= 0) {
					location.href = "../meihe/meihefh";
					clearInterval(interval);
				}
			}, 1000);
		})();
	</script>
</body>
</html>');
}
